<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />
    <ex_super_table_page v-bind="option" ref="SuperTablePage" @selection-change="e => selection = e"
      :cell-class-name="cellClassMethod" >
    </ex_super_table_page>

    <detail_tranfer_package ref="detail_tranfer_package" />
    <ex_super_dialog_form ref="formDialog" :title="dialogTitle" v-bind="dialog" @afterSubmitSuccess="submitAfter">
    </ex_super_dialog_form>

    <print_tranfer_package ref="print_tranfer_package" />

    <transfer_batch_pack_measure ref="transfer_batch_pack_measure" @submitSuccess="reload()"/>
  </div>
</template>
<script>
import transfer_batch_pack_measure from './dialog/transfer_batch_pack_measure.vue';


import print_tranfer_package from '@/component/print/print_tranfer_package'

import superTablePageFunction from '@/mixin/super-table-page-function';
import detail_tranfer_package from '@/component/wms/detail_tranfer_package.vue';


import page_table_model_manage from '@/mixin/page_table_model_manage';

import emitOnFunction from '@/mixin/emit-on-function';
const emitKey = 'transfer>package_list'
export default {
  title: "label_check_pack_record",
  mixins: [superTablePageFunction, emitOnFunction(emitKey), page_table_model_manage],
  components: { detail_tranfer_package, print_tranfer_package, transfer_batch_pack_measure },
  data() {
    return {
      selection: [],
      dialogDetailCode: "",
      dialogDetail: false,
      option: {
        search: {
          model: [
            { label: "label_package_code", key: "packageNoList", placeholder: 'tip_input_can_comma_separated' },
            {
              label: "测量状态", key: "measureStatus", type: 'select', enum: 'MeasureStatusEnum'
            },

            { label: "入库单号", key: "inboundCodeList", placeholder: 'tip_input_can_comma_separated' },

            { label: "箱号", key: "boxNoList", placeholder: 'tip_input_can_comma_separated' },

          ],
        },
        actionExtra: [
          {
            label: 'label_batch_measure', auth: 'wms_transfer_pack_measure', click: (row) => {
              this.$refs.transfer_batch_pack_measure.show({ tableList: this.selection })
            }
          },
          {
            label: "label_print", click: () => {
              if (_.isEmpty(this.selection)) return this.$message.error(this.$tt("tip_please_select_order"))
              this.$refs.print_tranfer_package.show(this.selection)
            }
          },

        ],
        table: {
          url: "/wms-api/inbound/WmsInboundTransitPackagingRpc/selectPage.json",
          model: this.init_table_model(),
        }
      },

      dialogTitle: '',
      dialog: {
        customClass: 'dialog_auto',
        submitUrl: '/wms-api/inbound/WmsInboundTransitPackagingRpc/measure.json',
        form: {
          itemClass: "form_item_mini", inputClass: "form_input_small",
          formClass: "form_mini_col2",
          inline: true,
          model: [
            { key: 'packageNo', label: 'label_package_code', formType: 'text', itemClass: "form_item_default", },
            {
              key: 'packagingName', label: 'label_pack_material_name', formType: 'text',
              formatter: (r, c, v, i) => this.$formatNameCode(v, r.packagingTypeName)
            },
            {
              key: 'destinationWarehouseName', label: 'label_destination_warehouse', formType: 'text',
              formatter: (r, c, v, i) => this.$formatNameCode(v, r.destinationWarehouseCode)
            },
            { key: 'inboundOrderQty', label: '入库单数量', formType: 'text', },
            { key: 'boxQty', label: '装箱数量', formType: 'text', },
            {
              key: 'weight', label: 'label_weight', append: 'kg', appendClass: 'input_slot_div_mini'
            },
            {
              key: 'length', label: 'label_length', append: 'cm', appendClass: 'input_slot_div_mini'
            },
            {
              key: 'width', label: 'label_width', append: 'cm', appendClass: 'input_slot_div_mini'
            },
            {
              key: 'height', label: 'label_height', append: 'cm', appendClass: 'input_slot_div_mini'
            },
          ],
          rules: {
            'weight': {
              required: true, validator: (r, v, cb) => {
                if (!this.$reg.DigitNumber(v, 3, 9)) {
                  return cb(this.$tt("tip_check_decimal_digit_int", { digit: 3, int: 9 }))
                }
                cb()
              }, trigger: 'change'
            },
            'length': {
              required: true, validator: (r, v, cb) => {
                if (!this.$reg.DigitNumber(v, 3, 9)) {
                  return cb(this.$tt("tip_check_decimal_digit_int", { digit: 3, int: 9 }))
                }
                cb()
              }, trigger: 'change'
            },
            'width': {
              required: true, validator: (r, v, cb) => {
                if (!this.$reg.DigitNumber(v, 3, 9)) {
                  return cb(this.$tt("tip_check_decimal_digit_int", { digit: 3, int: 9 }))
                }
                cb()
              }, trigger: 'change'
            },
            'height': {
              required: true, validator: (r, v, cb) => {
                if (!this.$reg.DigitNumber(v, 3, 9)) {
                  return cb(this.$tt("tip_check_decimal_digit_int", { digit: 3, int: 9 }))
                }
                cb()
              }, trigger: 'change'
            },
          },
        }
      },
    };
  },
  methods: {
    option_table_model() {
      return [
        { type: 'selection', clickToggle: true, },
        {
          type: 'expandDesc', 'width': 100,
          expandDesc: {
            class: "desc_flex_row",
            column: 4, border: true, direction: 'vertical', labelClassName: 'widthdiv4', contentClassName: 'widthdiv4',
            model: [],
          },
        },
        {
          key: 'packageNo', label: 'label_package_code', 'min-width': 170, //'show-overflow-tooltip': true,
          render: (h, { row, column }) => {
            const code = row[column.property]
            if (!code) return this.$tt('data_temp_none')
            return (<text_extra_tooltip_operate extra_barcode_image extra_text_align='center'
              value={code}
              data_type={column.property} data_id={row.id}
            />)
          },
     
        },

        {
          key: 'inboundOrderCodeList', label: 'label_inbound_code', 'width': 170,
          render: (h, { row }) => {
            if (row.inboundOrderCodeList) {
              return (
                row.inboundOrderCodeList.map(item => {
                  return <div class=''>{item}</div>
                })
              )
            }
          }
        },
        {
          key: 'packagingName', label: 'label_pack_material_name', 'min-width': 160, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$formatNameCode(v, r.packagingTypeName)
        },
        {
          key: 'weight', label: 'label_weight', 'width': 100, 'show-overflow-tooltip': true,
          formatter: (r, c, v) => this.$addUnit(this.$formatDigit(v), 'kg'),
        },
        {
          key: 'length', label: 'label_length', 'width': 100, 'show-overflow-tooltip': true,
          formatter: (r, c, v) => this.$addUnit(this.$formatDigit(v), 'cm'),
        },
        {
          key: 'width', label: 'label_width', 'width': 100, 'show-overflow-tooltip': true,
          formatter: (r, c, v) => this.$addUnit(this.$formatDigit(v), 'cm'),
        },
        {
          key: 'height', label: 'label_height', 'width': 100, 'show-overflow-tooltip': true,
          formatter: (r, c, v) => this.$addUnit(this.$formatDigit(v), 'cm'),
        },
        {
          key: 'destinationWarehouseName', label: 'label_destination_warehouse', 'width': 120, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$formatNameCode(v, r.destinationWarehouseCode)
        },
        {
          key: 'inboundOrderQty', label: '入库单数量', 'width': 100, 'show-overflow-tooltip': true,
        },
        {
          key: 'boxQty', label: '装箱数量', 'width': 100, 'show-overflow-tooltip': true,
        },
        {
          key: 'measureStatus', label: '测量状态', 'width': 120, 'show-overflow-tooltip': true, formatter: (r, c, v) => this.$enumShow(v, 'MeasureStatusEnum')
        },
        {
          type: 'operate', width: 210, fixed: 'right', operate: [
            {
              label: 'label_view_detail', click: (row) =>
                this.$refs.detail_tranfer_package.show({
                  params: { packageId: row.id },
                })
            },
            {
              label: 'label_measure', auth: 'wms_transfer_pack_measure', click: (row) => {
                this.dialogTitle = this.$tt('label_measure')
                this['$refs']['formDialog'].show(row, { setData: true })
              }
            },
            {
              label: "label_print", click: (row) => {
                this.$refs.print_tranfer_package.show([row])
              }
            },
          ]
        }
      ]
    },
    cellClassMethod({ row, column, rowIndex, columnIndex }) {
      if (column.property == 'status') {
        if (row.status == 'TRANSIT_WAIT_RECEIVING') {
          return 'color_primary'
        } else if (row.status == 'TRANSIT_WAIT_PICKING') {
          return 'color_primary'
        } else if (row.status == 'TRANSIT_PARTIAL_OUTBOUND') {
          return 'color_warning'
        } else if (row.status == 'TRANSIT_OUTBOUND') {
          return 'color_success'
        }
      }
      return ""
    },




    submitAfter() {
      this.reload()
      this.$emitPage("transfer=>checkout_list", 'reload')

    }
  }
};

</script>
<style></style>
